import React, { useState,useEffect } from 'react';
import { async_add,async_edit } from '../../store/crilsSlice';
import {useDispatch} from "react-redux"
import {
  Button,
  Cascader,
  DatePicker,
  Form,
  Input,
  InputNumber,
  Radio,
  Select,
  Switch,
  TreeSelect,
} from 'antd';
const Myfrom = (props) => {
  let dispatch=useDispatch()
      const [form] = Form.useForm();
      useEffect(()=>{
        form.setFieldsValue(props.itemObj)
      })
const onFinish = values => {
  if(props.titles=='添加'){
      let obj={
     "id": new Date().getTime(),
     ...values
  }
  dispatch(async_add(obj))
  }else{
    let obj={
      "id":props.itemObj.id,
      ...values
    }
    dispatch(async_edit(obj))
  }
props.onCancel()
  console.log('Success:', values);
};
  return (

  
  <Form
  onFinish={onFinish}
  form={form}
  >
    <Form.Item
      label="优惠卷名称"
      name="title"
      rules={[{ required: true, message: 'Please input your username!' }]}
    >
      <Input />
    </Form.Item>

    <Form.Item
      label="优惠卷面值"
      name="mian"
      rules={[{ required: true, message: 'Please input your password!' }]}
    >
      <Input />
    </Form.Item>
        <Form.Item
      label="优惠卷最低消费"
      name="min"
      rules={[{ required: true, message: 'Please input your password!' }]}
    >
      <Input />
    </Form.Item>
        <Form.Item
      label="优惠卷有效期限"
      name="day"
      rules={[{ required: true, message: 'Please input your password!' }]}
    >
      <Input />
    </Form.Item>
    <Form.Item
      label="排序"
      name="sort"
      rules={[{ required: true, message: 'Please input your password!' }]}
    >
      <Input />
    </Form.Item>
        <Form.Item
      label="状态"
      name="state"
    >
 <Radio.Group

    options={[
      { value: true, label: '开启' },
      { value: false, label: '关闭' },

    ]}
  />
    </Form.Item>

      <Button type="primary" htmlType="submit">
        Submit
      </Button>
   
  </Form>
  );
};
export default Myfrom;